/*
 * AudioView.java
 */

package audio.gui;

import audio.player.EchoFilter;
import audio.player.LowPassFilter;
import audio.player.SimpleAudioPlayer;
import audio.player.SimpleAudioPlayer.InvalidStateException;
import audio.player.SoundFilter;
import java.awt.CardLayout;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.UnsupportedAudioFileException;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.HashMap;
import javax.swing.DefaultComboBoxModel;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 * The application's main frame.
 */
public class AudioView extends FrameView {

    public AudioView(SingleFrameApplication app) {
        super(app);

        initComponents();
        songProgressBar.setIndeterminate(false);
        songProgressBar.setMinimum(0);
        songProgressBar.setMaximum(100);
        filterMap = new HashMap<Integer, SoundFilter>();
        filterMap.put(0, null);
        filterMap.put(1, new EchoFilter(22050, .4f));
        filterMap.put(2, new LowPassFilter(10));

        //player.setProgressListener(pl);
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = AudioApp.getApplication().getMainFrame();
            aboutBox = new AudioAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        AudioApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        pathField = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        browseButton = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        playButton = new javax.swing.JButton();
        pauseButton = new javax.swing.JButton();
        stopButton = new javax.swing.JButton();
        songProgressBar = new javax.swing.JProgressBar();
        jLabel2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        effectsBox = new javax.swing.JComboBox();
        effectAdjustContainer = new javax.swing.JPanel();
        emptyPanel = new javax.swing.JPanel();
        echoPanel = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        echoDelay = new javax.swing.JSlider();
        echoDecay = new javax.swing.JSlider();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();

        mainPanel.setName("mainPanel"); // NOI18N

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(audio.gui.AudioApp.class).getContext().getResourceMap(AudioView.class);
        pathField.setText(resourceMap.getString("pathField.text")); // NOI18N
        pathField.setName("pathField"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        browseButton.setText(resourceMap.getString("browseButton.text")); // NOI18N
        browseButton.setName("browseButton"); // NOI18N
        browseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                browseButtonActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("controlsContainer.border.title"))); // NOI18N
        jPanel1.setName("controlsContainer"); // NOI18N

        playButton.setText(resourceMap.getString("playButton.text")); // NOI18N
        playButton.setName("playButton"); // NOI18N
        playButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                playButtonActionPerformed(evt);
            }
        });

        pauseButton.setText(resourceMap.getString("pauseButton.text")); // NOI18N
        pauseButton.setName("pauseButton"); // NOI18N
        pauseButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                pauseButtonActionPerformed(evt);
            }
        });

        stopButton.setText(resourceMap.getString("stopButton.text")); // NOI18N
        stopButton.setName("stopButton"); // NOI18N
        stopButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stopButtonActionPerformed(evt);
            }
        });

        songProgressBar.setName("songProgressBar"); // NOI18N

        jLabel2.setText(resourceMap.getString("timeLabel.text")); // NOI18N
        jLabel2.setName("timeLabel"); // NOI18N

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(playButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(pauseButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(stopButton)
                        .addGap(18, 18, 18)
                        .addComponent(songProgressBar, javax.swing.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addContainerGap(366, Short.MAX_VALUE)
                        .addComponent(jLabel2)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(songProgressBar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(playButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(pauseButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(stopButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addContainerGap())
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel2.border.title"))); // NOI18N
        jPanel2.setName("jPanel2"); // NOI18N

        effectsBox.setModel(model);
        effectsBox.setActionCommand(resourceMap.getString("effectsComboBox.actionCommand")); // NOI18N
        effectsBox.setName("effectsComboBox"); // NOI18N
        effectsBox.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                effectsBoxItemStateChanged(evt);
            }
        });
        effectsBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                effectsBoxActionPerformed(evt);
            }
        });

        effectAdjustContainer.setName("effectAdjustContainer"); // NOI18N
        effectAdjustContainer.setLayout(new java.awt.CardLayout());

        emptyPanel.setName("emptyPanel"); // NOI18N

        javax.swing.GroupLayout emptyPanelLayout = new javax.swing.GroupLayout(emptyPanel);
        emptyPanel.setLayout(emptyPanelLayout);
        emptyPanelLayout.setHorizontalGroup(
            emptyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 390, Short.MAX_VALUE)
        );
        emptyPanelLayout.setVerticalGroup(
            emptyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 94, Short.MAX_VALUE)
        );

        effectAdjustContainer.add(emptyPanel, "Brak");

        echoPanel.setName("echoPanel"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        echoDelay.setMajorTickSpacing(2);
        echoDelay.setMaximum(9);
        echoDelay.setMinimum(1);
        echoDelay.setMinorTickSpacing(1);
        echoDelay.setPaintLabels(true);
        echoDelay.setPaintTicks(true);
        echoDelay.setSnapToTicks(true);
        echoDelay.setValue(5);
        echoDelay.setName("echoDelay"); // NOI18N
        echoDelay.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                echoDelayStateChanged(evt);
            }
        });

        echoDecay.setMajorTickSpacing(2);
        echoDecay.setMaximum(9);
        echoDecay.setMinimum(1);
        echoDecay.setMinorTickSpacing(1);
        echoDecay.setPaintLabels(true);
        echoDecay.setPaintTicks(true);
        echoDecay.setSnapToTicks(true);
        echoDecay.setValue(5);
        echoDecay.setName("echoDecay"); // NOI18N
        echoDecay.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                echoDecayStateChanged(evt);
            }
        });

        javax.swing.GroupLayout echoPanelLayout = new javax.swing.GroupLayout(echoPanel);
        echoPanel.setLayout(echoPanelLayout);
        echoPanelLayout.setHorizontalGroup(
            echoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, echoPanelLayout.createSequentialGroup()
                .addGroup(echoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(echoDelay, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(echoPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel3)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 52, Short.MAX_VALUE)
                .addGroup(echoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(echoPanelLayout.createSequentialGroup()
                        .addComponent(echoDecay, 0, 0, Short.MAX_VALUE)
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, echoPanelLayout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(143, 143, 143))))
        );
        echoPanelLayout.setVerticalGroup(
            echoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(echoPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(echoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(echoPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(echoDecay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(echoDelay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(18, Short.MAX_VALUE))
        );

        effectAdjustContainer.add(echoPanel, "Echo");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(effectAdjustContainer, javax.swing.GroupLayout.DEFAULT_SIZE, 390, Short.MAX_VALUE)
                    .addComponent(effectsBox, javax.swing.GroupLayout.PREFERRED_SIZE, 224, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(effectsBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(effectAdjustContainer, javax.swing.GroupLayout.DEFAULT_SIZE, 94, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(pathField, javax.swing.GroupLayout.DEFAULT_SIZE, 371, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(browseButton))
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING))
                .addContainerGap())
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(2, 2, 2)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(pathField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(browseButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(audio.gui.AudioApp.class).getContext().getActionMap(AudioView.class, this);
        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        setComponent(mainPanel);
        setMenuBar(menuBar);
    }// </editor-fold>//GEN-END:initComponents

    private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
        int choice = fileChooser.showOpenDialog(mainPanel);
        if(choice == JFileChooser.CANCEL_OPTION)
            return;
        File file = fileChooser.getSelectedFile();

        //jakies sprawdzanie tu jeszcze
        audioFile = file;
        pathField.setText(file.getAbsolutePath());
        try {
            player.setSource(file);
        } catch (UnsupportedAudioFileException ex) {
            JOptionPane.showMessageDialog(mainPanel, ex.getMessage());
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(mainPanel, ex.getMessage());
        }
    }//GEN-LAST:event_browseButtonActionPerformed

    private void playButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_playButtonActionPerformed
        try {
            player.play();
        } catch (InvalidStateException ex) {
            JOptionPane.showMessageDialog(mainPanel, ex.getMessage());
        }
    }//GEN-LAST:event_playButtonActionPerformed

    private void pauseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pauseButtonActionPerformed
       player.pause();
    }//GEN-LAST:event_pauseButtonActionPerformed

    private void stopButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stopButtonActionPerformed
        player.stop();
    }//GEN-LAST:event_stopButtonActionPerformed

    private void effectsBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_effectsBoxActionPerformed
        int selection = effectsBox.getSelectedIndex();
        player.setFilter(filterMap.get(selection));


    }//GEN-LAST:event_effectsBoxActionPerformed

    private void effectsBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_effectsBoxItemStateChanged
        CardLayout layout = (CardLayout)effectAdjustContainer.getLayout();
        layout.show(effectAdjustContainer, (String)evt.getItem());
    }//GEN-LAST:event_effectsBoxItemStateChanged

    private void echoDelayStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_echoDelayStateChanged
        if (!echoDelay.getValueIsAdjusting()) {
            int value = (int)echoDelay.getValue();
            int delay = value * 5512;
            ((EchoFilter)filterMap.get(1)).setDelaySamples(delay);
        }
    }//GEN-LAST:event_echoDelayStateChanged

    private void echoDecayStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_echoDecayStateChanged

        if (!echoDecay.getValueIsAdjusting()) {
            int value = (int)echoDecay.getValue();
            float decay = value * 0.1f;
            ((EchoFilter)filterMap.get(1)).setDecay(decay);
        }

    }//GEN-LAST:event_echoDecayStateChanged

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton browseButton;
    private javax.swing.JSlider echoDecay;
    private javax.swing.JSlider echoDelay;
    private javax.swing.JPanel echoPanel;
    private javax.swing.JPanel effectAdjustContainer;
    private javax.swing.JComboBox effectsBox;
    private javax.swing.JPanel emptyPanel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JTextField pathField;
    private javax.swing.JButton pauseButton;
    private javax.swing.JButton playButton;
    private javax.swing.JProgressBar songProgressBar;
    private javax.swing.JButton stopButton;
    // End of variables declaration//GEN-END:variables

    //private final Timer messageTimer;
    //private final Timer busyIconTimer;
    //private final Icon idleIcon;
    //private final Icon[] busyIcons = new Icon[15];
    //private int busyIconIndex = 0;

    private JDialog aboutBox;
    private final JFileChooser fileChooser = new JFileChooser();
    private File audioFile;
    private SimpleAudioPlayer player=new SimpleAudioPlayer();

    private String[] effects = {"Brak", "Echo", "Dolno-przepustowy"};
    private DefaultComboBoxModel model = new DefaultComboBoxModel(effects);
    private HashMap<Integer, SoundFilter> filterMap;

    private SimpleAudioPlayer.ProgressListener pl = new SimpleAudioPlayer.ProgressListener() {

        public void onPlay() {
        }

        public void onProgress(long elapsed, long total) {
            int prog = (int) ((elapsed * 100) / total);
            songProgressBar.setValue(prog);
        }

        public void onPause() {
        }

        public void onStop() {
        }
    };
}
